import $ from '../common';
Page({
  data: {
    active:0,
    tip:'上滑记载更加多',
    list:[],
    page:1,
  },
  onLoad(options) {
    this.setData({
      zonecode: wx.getStorageSync('addresscode') || ''
    })
    this.reset()
  },
  onShow() {

  },
  onReachBottom() {

  },
  onChange(e){
    this.setData({
      active:e.detail.index
    })
    this.reset()
  },
  reset(){
    this.setData({
      tip:'上滑记载更加多',
      page:1,
      list:[]
    })
    this.getlist()
  },
  getlist(){
    let url='/user/lesson/review/waiting'
    if(this.data.active==1)url='/user/lesson/review/list'
    $.get(url,{
      zonecode:this.data.zonecode,
      page:this.data.page,
      limit:20,
    },res=>{
      let arr=this.data.active==0?res.waiting_review_lessons:res.reviews
      if(arr.length<20){
        this.data.tip='已经到底了'
      }else{
        this.data.tip='上滑加载更多'
      }
      this.data.page++
      this.setData({
        list:[...this.data.list,...arr],
        page:this.data.page,
        tip:this.data.tip
      })
    })
  },
  godetail(e){
    const{lesson_uuid,student_uuid}=e.currentTarget.dataset
    $.navigateTo(`/classroom/estimatedetail?lesson_uuid=${lesson_uuid}&student_uuid=${student_uuid}`)
  }
})